﻿@model InfoTech.VinhSon.Models.ArticleModel
@{
    ViewBag.Title = "Edit Article";
    ViewBag.MnuLevel1 = "database";
    ViewBag.MnuLevel2 = "article";
    Layout = "~/Areas/Administrator/Views/Shared/_Layout.cshtml";
}
@section navigation
{
    <ul class="breadcrumbs">
        <li><a href="@Url.Action("Index",
                                 "Dashboard")"><i class="iconfa-home"></i></a><span class="separator">
                                                                              </span></li>
        <li><a href="@Url.Action("Index")">Article Management</a><span class="separator"> </span>
        </li>
        <li>Edit Article</li>
    </ul>
}
@section header
{
    <div class="pageheader">
        <div class="pageicon">
            <span class="iconfa-tag"></span>
        </div>
        <div class="pagetitle">
            <h1>
                Edit Article</h1>
        </div>
    </div>
}
@section script
{
    <script src="@Url.Content("~/Scripts/ckeditor/ckeditor.js")"> </script>
    <script src="@Url.Content("~/Areas/Administrator/Content/js/htmleditor.js")"> </script>
    <script type="text/javascript">
        function addDocument() {
            var window = $("#winAddDocument").data("tWindow");
            $("#winAddDocument iframe").attr('src', '@Url.Action("AddDocument",
                                                                 new
                                                                     {
                                                                             Model.Id
                                                                     })');
            window.maximize();
            window.open();
        }

        function closeWindowAddDocument(obj) {
            var window = $("#winAddDocument").data("tWindow");
            window.close();
            if (obj)
                $("#SectionGrid").data("tGrid").ajaxRequest();
        }

        function addSection() {
            var window = $("#winAddSection").data("tWindow");
            $("#winAddSection iframe").attr('src', '@Url.Action("AddSection",
                                                                new
                                                                    {
                                                                            Model.Id
                                                                    })');
            window.maximize();
            window.open();
        }

        function closeWindowAddSection(obj) {
            var window = $("#winAddSection").data("tWindow");
            window.close();
            if (obj)
                $("#SectionGrid").data("tGrid").ajaxRequest();
        }

        function addImage() {
            var window = $("#winAddImage").data("tWindow");
            $("#winAddImage iframe").attr('src', '@Url.Action("AddImage",
                                                              new
                                                                  {
                                                                          Model.Id
                                                                  })');
            window.maximize();
            window.open();
        }

        function closeWindowAddImage(obj) {
            var window = $("#winAddImage").data("tWindow");
            window.close();
            if (obj)
                $("#SectionGrid").data("tGrid").ajaxRequest();
        }

        function addVideo() {
            var window = $("#winAddVideo").data("tWindow");
            $("#winAddVideo iframe").attr('src', '@Url.Action("AddVideo",
                                                              new
                                                                  {
                                                                          Model.Id
                                                                  })');
            window.maximize();
            window.open();
        }

        function closeWindowAddVideo(obj) {
            var window = $("#winAddVideo").data("tWindow");
            window.close();
            if (obj)
                $("#SectionGrid").data("tGrid").ajaxRequest();
        }

        function Delete(id) {
            if (confirm("Do you want to delete?"))
                $.post('@Url.Action("DeleteSection",
                                    "Article")', { id: id }, function(data) {
                    showNotification(data);
                    $("#SectionGrid").data("tGrid").ajaxRequest();
                });
        }

        function edit(id, type) {
            if (type == 1)
                editSection(id);
            else if (type == 2)
                editDocument(id);
            else if (type == 3)
                editImage(id);
            else if (type == 4)
                editVideo(id);
        }

        function editSection(id) {
            var window = $("#winEditSection").data("tWindow");
            $("#winEditSection iframe").attr('src', '@Url.Action("EditSection")/' + id);
            window.maximize();
            window.open();
        }

        function closeWindowEditSection(obj) {
            var window = $("#winEditSection").data("tWindow");
            window.close();
            if (obj)
                $("#SectionGrid").data("tGrid").ajaxRequest();
        }

        function editDocument(id) {
            var window = $("#winEditDocument").data("tWindow");
            $("#winEditDocument iframe").attr('src', '@Url.Action("EditDocument")/' + id);
            window.maximize();
            window.open();
        }

        function closeWindowEditDocument(obj) {
            var window = $("#winEditDocument").data("tWindow");
            window.close();
            if (obj)
                $("#SectionGrid").data("tGrid").ajaxRequest();
        }

        function editImage(id) {
            var window = $("#winEditImage").data("tWindow");
            $("#winEditImage iframe").attr('src', '@Url.Action("EditImage")/' + id);
            window.maximize();
            window.open();
        }

        function closeWindowEditImage(obj) {
            var window = $("#winEditImage").data("tWindow");
            window.close();
            if (obj)
                $("#SectionGrid").data("tGrid").ajaxRequest();
        }

        function editVideo(id) {
            var window = $("#winEditVideo").data("tWindow");
            $("#winEditVideo iframe").attr('src', '@Url.Action("EditVideo")/' + id);
            window.maximize();
            window.open();
        }

        function closeWindowEditVideo(obj) {
            var window = $("#winEditVideo").data("tWindow");
            window.close();
            if (obj)
                $("#SectionGrid").data("tGrid").ajaxRequest();
        }

        function updateStatusOption(key, id) {
            $.post('@Url.Action("UpdateOption")', { id: '@Model.Id', key: key, status: $('#' + id)[0].checked }, function(data) {
                showNotification(data);
            });
        }

        function updateGroup() {
            var arr = new Array();
            var obj = $('.group-panel input[type="checkbox"]');
            for (var i = 0; i < obj.length; i++)
                if (obj[i].checked)
                    arr.push($(obj[i]).attr('gid'));
            $.post('@Url.Action("UpdateGroup")', { id: '@Model.Id', ids: arr.toString() }, function (data) {
                showNotification(data);
            });
        }

        function addGroup() {
            var window = $("#winAddGroup").data("tWindow");
            $("#winAddGroup iframe").attr('src', '@Url.Action("AddArticleGroup",
                                                              new
                                                                  {
                                                                          Model.Id
                                                                  })');
            window.maximize();
            window.open();
        }

        function closeWindowAddGroup(obj) {
            var window = $("#winAddGroup").data("tWindow");
            window.close();
            if (obj)
                $("#GroupGrid").data("tGrid").ajaxRequest();
        }
        
        function editGroup(id) {
            var window = $("#winEditGroup").data("tWindow");
            $("#winEditGroup iframe").attr('src', '@Url.Action("EditArticleGroup")/' + id);
            window.maximize();
            window.open();
        }

        function closeWindowEditGroup(obj) {
            var window = $("#winEditGroup").data("tWindow");
            window.close();
            if (obj)
                $("#GroupGrid").data("tGrid").ajaxRequest();
        }
        
        function deleteGroup(id) {
            if (confirm("Do you want to delete?"))
                $.post('@Url.Action("DeleteArticleGroup",
                                    "Article")', { id: id }, function(data) {
                    showNotification(data);
                    $("#GroupGrid").data("tGrid").ajaxRequest();
                });
        }

    </script>
}
@Html.ValidationSummary()
<div class="widgetbox">
    <h4 class="widgettitle">
        Edit Article</h4>
    <div class="widgetcontent nopadding">
        <form class="stdform stdform2" enctype="multipart/form-data" method="POST">
            @Html.HiddenFor(c => c.Id)
            <p>
                <label>
                    Category</label>
                <span class="field">
                    @Html.DropDownListFor(c => c.CategoryId,
                                          (IEnumerable<SelectListItem>) ViewBag.Categories,
                                          new
                                              {
                                                      @class = "uniformselect"
                                              })
                    @Html.ValidationMessageFor(c => c.Name)
                </span>
            </p>
            <p>
                <label>
                    Name</label>
                <span class="field">
                    @Html.TextBoxFor(c => c.Name,
                                     new
                                         {
                                                 @class = "input-xlarge",
                                                 placeholder = "Name"
                                         })
                    @Html.ValidationMessageFor(c => c.Name)
                </span>
            </p>
            <p>
                <label>
                    Thumbnail</label>
                <span class="field">
                    @{
                        if(!string.IsNullOrEmpty(Model.Thumbnail))
                        {
                            <img src="/Resource/Article/@Model.Thumbnail" width="300"/>
                            <br />
                        }
                    }
                    <input name="upload" type="file" />
                </span>
            </p>
            <p>
                <label>
                    Link</label>
                <span class="field">
                    @Html.TextBoxFor(c => c.Link,
                                     new
                                         {
                                                 @class = "input-xxlarge",
                                                 placeholder = "Link"
                                         })
                    @Html.ValidationMessageFor(c => c.Link)
                </span>
            </p>
            <p>
                <label>
                    Description</label>
                <div class="field">
                    @Html.TextAreaFor(c => c.Description,
                                      new
                                          {
                                                  @class = "input-xxlarge",
                                                  placeholder = "Description"
                                          })
                    @Html.ValidationMessageFor(c => c.Description)
                </div>
            </p>
            <p>
                <label>
                    Detail</label>
                <div class="field">
                    @Html.TextAreaFor(c => c.Detail,
                                      new
                                          {
                                                  @class = "input-xlarge html-editor",
                                                  placeholder = "Detail"
                                          })
                    @Html.ValidationMessageFor(c => c.Detail)
                </div>
            </p>
            <p>
                <label>
                    Activated</label>
                <span class="field">
                    @Html.CheckBoxFor(c => c.Activated)
                    @Html.ValidationMessageFor(c => c.Activated)
                </span>
            </p>
            <p class="stdformbutton">
                <label>
                </label>
                <input type="submit" value="Update" class="btn btn-primary" />
                <input type="reset" value="Cancel" class="btn" />
            </p>
        </form>
    </div>
</div>
<div class="notification-box">
</div>
@(Html.Telerik()
      .TabStrip()
      .Name("tab")
      .Items(tab =>
                 {
                     tab.Add()
                        .Text("Multisections")
                        .Content(Html.Action("Section")
                                     .ToHtmlString());
                     tab.Add()
                        .Text("Static Group")
                        .Content(Html.Action("Group",
                                             Model)
                                     .ToHtmlString());
                     tab.Add()
                        .Text("Dynamic Group")
                        .Content(Html.Action("DynamicGroup",
                                             Model.Id)
                                     .ToHtmlString());
                     tab.Add()
                        .Text("Option")
                        .Content(Html.Action("Option",
                                             Model)
                                     .ToHtmlString());
                 })
      .SelectedIndex(0))
@(Html.Telerik()
      .Window()
      .Name("winAddDocument")
      .Width(850)
      .Height(400)
      .Title("Add Document")
      .Draggable(true)
      .Visible(false)
      .Buttons(buttons => buttons.Clear())
      .Content("<iframe src=\"" + Url.Action("Blank") + "\" frameborder=\"0\" style=\"width: 99%; height: 99%\"></iframe>")
      .Scrollable(false))
@(Html.Telerik()
      .Window()
      .Name("winEditDocument")
      .Width(850)
      .Height(400)
      .Title("Edit Document")
      .Draggable(true)
      .Visible(false)
      .Buttons(buttons => buttons.Clear())
      .Content("<iframe src=\"" + Url.Action("Blank") + "\" frameborder=\"0\" style=\"width: 99%; height: 99%\"></iframe>")
      .Scrollable(false))
@(Html.Telerik()
      .Window()
      .Name("winAddSection")
      .Width(850)
      .Height(400)
      .Title("Add Section")
      .Draggable(true)
      .Visible(false)
      .Buttons(buttons => buttons.Clear())
      .Content("<iframe src=\"" + Url.Action("Blank") + "\" frameborder=\"0\" style=\"width: 99%; height: 99%\"></iframe>")
      .Scrollable(false))
@(Html.Telerik()
      .Window()
      .Name("winEditSection")
      .Width(850)
      .Height(400)
      .Title("Edit Section")
      .Draggable(true)
      .Visible(false)
      .Buttons(buttons => buttons.Clear())
      .Content("<iframe src=\"" + Url.Action("Blank") + "\" frameborder=\"0\" style=\"width: 99%; height: 99%\"></iframe>")
      .Scrollable(false))
@(Html.Telerik()
      .Window()
      .Name("winAddImage")
      .Width(800)
      .Height(400)
      .Title("Add Image")
      .Draggable(true)
      .Buttons(buttons => buttons.Clear())
      .Content("<iframe src=\"" + Url.Action("Blank") + "\" frameborder=\"0\" style=\"width: 99%; height: 99%\"></iframe>")
      .Visible(false))
@(Html.Telerik()
      .Window()
      .Name("winEditImage")
      .Width(800)
      .Height(400)
      .Title("Edit Image")
      .Draggable(true)
      .Buttons(buttons => buttons.Clear())
      .Content("<iframe src=\"" + Url.Action("Blank") + "\" frameborder=\"0\" style=\"width: 99%; height: 99%\"></iframe>")
      .Visible(false))
@(Html.Telerik()
      .Window()
      .Name("winAddVideo")
      .Width(400)
      .Height(300)
      .Title("Add Video")
      .Draggable(true)
      .Buttons(buttons => buttons.Clear())
      .Content("<iframe src=\"" + Url.Action("Blank") + "\" frameborder=\"0\" style=\"width: 99%; height: 99%\"></iframe>")
      .Visible(false))
@(Html.Telerik()
      .Window()
      .Name("winEditVideo")
      .Width(400)
      .Height(300)
      .Title("Edit Video")
      .Draggable(true)
      .Buttons(buttons => buttons.Clear())
      .Content("<iframe src=\"" + Url.Action("Blank") + "\" frameborder=\"0\" style=\"width: 99%; height: 99%\"></iframe>")
      .Visible(false))
@(Html.Telerik()
      .Window()
      .Name("winAddGroup")
      .Width(400)
      .Height(300)
      .Title("Add Group")
      .Draggable(true)
      .Content("<iframe src=\"" + Url.Action("Blank") + "\" frameborder=\"0\" style=\"width: 99%; height: 99%\"></iframe>")
      .Visible(false))
@(Html.Telerik()
      .Window()
      .Name("winEditGroup")
      .Width(400)
      .Height(300)
      .Title("Edit Group")
      .Draggable(true)
      .Content("<iframe src=\"" + Url.Action("Blank") + "\" frameborder=\"0\" style=\"width: 99%; height: 99%\"></iframe>")
      .Visible(false))